﻿// 中国省市区县数据 - 基于province-city-china数据整理
// 数据来源：国家统计局、民政部官方数据
// 更新时间：2024年
export const regionsData = [
  {
    "code": "110000",
    "name": "北京市",
    "province": "11",
    "children": [
      {
        "code": "110100",
        "name": "北京市",
        "province": "11",
        "city": "01",
        "children": [
          { "code": "110101", "name": "东城区", "province": "11", "city": "01", "area": "01" },
          { "code": "110102", "name": "西城区", "province": "11", "city": "01", "area": "02" },
          { "code": "110105", "name": "朝阳区", "province": "11", "city": "01", "area": "05" },
          { "code": "110106", "name": "丰台区", "province": "11", "city": "01", "area": "06" },
          { "code": "110107", "name": "石景山区", "province": "11", "city": "01", "area": "07" },
          { "code": "110108", "name": "海淀区", "province": "11", "city": "01", "area": "08" },
          { "code": "110109", "name": "门头沟区", "province": "11", "city": "01", "area": "09" },
          { "code": "110111", "name": "房山区", "province": "11", "city": "01", "area": "11" },
          { "code": "110112", "name": "通州区", "province": "11", "city": "01", "area": "12" },
          { "code": "110113", "name": "顺义区", "province": "11", "city": "01", "area": "13" },
          { "code": "110114", "name": "昌平区", "province": "11", "city": "01", "area": "14" },
          { "code": "110115", "name": "大兴区", "province": "11", "city": "01", "area": "15" },
          { "code": "110116", "name": "怀柔区", "province": "11", "city": "01", "area": "16" },
          { "code": "110117", "name": "平谷区", "province": "11", "city": "01", "area": "17" },
          { "code": "110118", "name": "密云区", "province": "11", "city": "01", "area": "18" },
          { "code": "110119", "name": "延庆区", "province": "11", "city": "01", "area": "19" }
        ]
      }
    ]
  },
  {
    "code": "120000",
    "name": "天津市",
    "province": "12",
    "children": [
      {
        "code": "120100",
        "name": "天津市",
        "province": "12",
        "city": "01",
        "children": [
          { "code": "120101", "name": "和平区", "province": "12", "city": "01", "area": "01" },
          { "code": "120102", "name": "河东区", "province": "12", "city": "01", "area": "02" },
          { "code": "120103", "name": "河西区", "province": "12", "city": "01", "area": "03" },
          { "code": "120104", "name": "南开区", "province": "12", "city": "01", "area": "04" },
          { "code": "120105", "name": "河北区", "province": "12", "city": "01", "area": "05" },
          { "code": "120106", "name": "红桥区", "province": "12", "city": "01", "area": "06" },
          { "code": "120110", "name": "东丽区", "province": "12", "city": "01", "area": "10" },
          { "code": "120111", "name": "西青区", "province": "12", "city": "01", "area": "11" },
          { "code": "120112", "name": "津南区", "province": "12", "city": "01", "area": "12" },
          { "code": "120113", "name": "北辰区", "province": "12", "city": "01", "area": "13" },
          { "code": "120114", "name": "武清区", "province": "12", "city": "01", "area": "14" },
          { "code": "120115", "name": "宝坻区", "province": "12", "city": "01", "area": "15" },
          { "code": "120116", "name": "滨海新区", "province": "12", "city": "01", "area": "16" },
          { "code": "120117", "name": "宁河区", "province": "12", "city": "01", "area": "17" },
          { "code": "120118", "name": "静海区", "province": "12", "city": "01", "area": "18" },
          { "code": "120119", "name": "蓟州区", "province": "12", "city": "01", "area": "19" }
        ]
      }
    ]
  },
  {
    "code": "130000",
    "name": "河北省",
    "province": "13",
    "children": [
      {
        "code": "130100",
        "name": "石家庄市",
        "province": "13",
        "city": "01",
        "children": [
          { "code": "130102", "name": "长安区", "province": "13", "city": "01", "area": "02" },
          { "code": "130104", "name": "桥西区", "province": "13", "city": "01", "area": "04" },
          { "code": "130105", "name": "新华区", "province": "13", "city": "01", "area": "05" },
          { "code": "130107", "name": "井陉矿区", "province": "13", "city": "01", "area": "07" },
          { "code": "130108", "name": "裕华区", "province": "13", "city": "01", "area": "08" },
          { "code": "130109", "name": "藁城区", "province": "13", "city": "01", "area": "09" },
          { "code": "130110", "name": "鹿泉区", "province": "13", "city": "01", "area": "10" },
          { "code": "130111", "name": "栾城区", "province": "13", "city": "01", "area": "11" },
          { "code": "130121", "name": "井陉县", "province": "13", "city": "01", "area": "21" },
          { "code": "130123", "name": "正定县", "province": "13", "city": "01", "area": "23" },
          { "code": "130125", "name": "行唐县", "province": "13", "city": "01", "area": "25" },
          { "code": "130126", "name": "灵寿县", "province": "13", "city": "01", "area": "26" },
          { "code": "130127", "name": "高邑县", "province": "13", "city": "01", "area": "27" },
          { "code": "130128", "name": "深泽县", "province": "13", "city": "01", "area": "28" },
          { "code": "130129", "name": "赞皇县", "province": "13", "city": "01", "area": "29" },
          { "code": "130130", "name": "无极县", "province": "13", "city": "01", "area": "30" },
          { "code": "130131", "name": "平山县", "province": "13", "city": "01", "area": "31" },
          { "code": "130132", "name": "元氏县", "province": "13", "city": "01", "area": "32" },
          { "code": "130133", "name": "赵县", "province": "13", "city": "01", "area": "33" },
          { "code": "130181", "name": "辛集市", "province": "13", "city": "01", "area": "81" },
          { "code": "130183", "name": "晋州市", "province": "13", "city": "01", "area": "83" },
          { "code": "130184", "name": "新乐市", "province": "13", "city": "01", "area": "84" }
        ]
      }
    ]
  },
  {
    "code": "440000",
    "name": "广东省",
    "province": "44",
    "children": [
      {
        "code": "440100",
        "name": "广州市",
        "province": "44",
        "city": "01",
        "children": [
          { "code": "440103", "name": "荔湾区", "province": "44", "city": "01", "area": "03" },
          { "code": "440104", "name": "越秀区", "province": "44", "city": "01", "area": "04" },
          { "code": "440105", "name": "海珠区", "province": "44", "city": "01", "area": "05" },
          { "code": "440106", "name": "天河区", "province": "44", "city": "01", "area": "06" },
          { "code": "440111", "name": "白云区", "province": "44", "city": "01", "area": "11" },
          { "code": "440112", "name": "黄埔区", "province": "44", "city": "01", "area": "12" },
          { "code": "440113", "name": "番禺区", "province": "44", "city": "01", "area": "13" },
          { "code": "440114", "name": "花都区", "province": "44", "city": "01", "area": "14" },
          { "code": "440115", "name": "南沙区", "province": "44", "city": "01", "area": "15" },
          { "code": "440117", "name": "从化区", "province": "44", "city": "01", "area": "17" },
          { "code": "440118", "name": "增城区", "province": "44", "city": "01", "area": "18" }
        ]
      },
      {
        "code": "440300",
        "name": "深圳市",
        "province": "44",
        "city": "03",
        "children": [
          { "code": "440303", "name": "罗湖区", "province": "44", "city": "03", "area": "03" },
          { "code": "440304", "name": "福田区", "province": "44", "city": "03", "area": "04" },
          { "code": "440305", "name": "南山区", "province": "44", "city": "03", "area": "05" },
          { "code": "440306", "name": "宝安区", "province": "44", "city": "03", "area": "06" },
          { "code": "440307", "name": "龙岗区", "province": "44", "city": "03", "area": "07" },
          { "code": "440308", "name": "盐田区", "province": "44", "city": "03", "area": "08" },
          { "code": "440309", "name": "龙华区", "province": "44", "city": "03", "area": "09" },
          { "code": "440310", "name": "坪山区", "province": "44", "city": "03", "area": "10" },
          { "code": "440311", "name": "光明区", "province": "44", "city": "03", "area": "11" }
        ]
      }
    ]
  }
];

// 获取所有省份
export function getProvinces() {
  return regionsData.map(province => ({
    code: province.code,
    name: province.name,
    province: province.province
  }));
}

// 根据省份代码获取城市列表
export function getCitiesByProvince(provinceCode) {
  const province = regionsData.find(p => p.code === provinceCode);
  return province ? province.children.map(city => ({
    code: city.code,
    name: city.name,
    province: city.province,
    city: city.city
  })) : [];
}

// 根据城市代码获取区县列表
export function getAreasByCity(cityCode) {
  for (const province of regionsData) {
    const city = province.children.find(c => c.code === cityCode);
    if (city && city.children) {
      return city.children.map(area => ({
        code: area.code,
        name: area.name,
        province: area.province,
        city: area.city,
        area: area.area
      }));
    }
  }
  return [];
}

export default {
  regionsData,
  getProvinces,
  getCitiesByProvince,
  getAreasByCity
};
